/**
* @name ksg.ui.grid.columnTypes
* @namespace
* A collection of column types available to the grid.
* @Depends ksg.gridCore.js
*/
(function ($) {
	$.extend(ksg.ui.grid.columnTypes, /** @lends ksg.ui.grid.columnTypes */{
		/**
		* @class
		* Displays text and uses inline editing for the text.  Not a full HTML editor.
		*/
		text: {
			std: function(grid, col, bizObj, isEditabled) {
				var s = "<div tabindex='0' cellType='text' class='ksg-grid-cellEditor ksg-grid-textcell'";
				var fieldName = grid._getDataFieldId(col); 
				var v = "${" + fieldName + "}";
				try {
					if(!grid.dataHandler.hasValue(bizObj,fieldName))
						v = "";
				}
				catch(e) {
					v = "";
				}
				
				if(isEditabled == true)
					s+= " contentEditable='true'";
				s += ">" + v + "</div>";
				return s;
			},
			edit: function(grid, $gcol, $cell, col, bizObj) {
				$cell.focus();
			}
		},
		/**
		* @class
		* Displays an anchor link in the cell that the user can click on to navigate to the given location.
		*/
        link: {
            std: function (grid, col, bizObj, isEditabled) {
                var s = "<a href cellType='text' class='ksg-grid-cellLink ksg-grid-textcell'";
                var fieldName = grid._getDataFieldId(col);
                var v = "${" + fieldName + "}";
                try {
                    if (!grid.dataHandler.hasValue(bizObj, fieldName))
                        v = "";
                }
                catch (e) {
                    v = "";
                }
                s += ">" + v + "</a>";
                return s;
            },
            edit: function (grid, $gcol, $cell, col, bizObj) {
                $cell.focus();
            }
        },
		/**
		* @class
		* Displays an HTML checkbox for boolean values.  When editable, user can check the checkbox.
		*/
		checkbox: {
			std: function(grid, col, bizObj, isEditabled) {
				var s = "<input tabindex='0' cellType='checkbox' class='ksg-grid-cellEditor' ";
				if(isEditabled != true)
					s+= "disabled ";
				s += "type='checkbox' id='" + col.id + "' {{if (" + grid._getDataFieldId(col) + " == true)}}checked{{/if}} />";
				return s;
			},
			edit: function(grid, $gcol, $cell, col, bizObj) {
				$cell.focus();
			}		
		},
		/**
		* @class
		* Displays an image in the cell.
		*/
		image: {
			_defaultBlankImage: "/images/blank.gif",
			std: function(grid, col, bizObj, isEditabled) {
				var s = "";
				var resourceUrl = col.resourceUrl;
				if(!resourceUrl)
					resourceUrl = "";
				var imageSize = col.imageSize;
				if(!imageSize)
					imageSize = "TinyGridSize";
				var fieldName = grid._getDataFieldId(col); 
				var imgVal = grid.dataHandler.getValue(bizObj, fieldName);
				var shouldShowImage = (imgVal && imgVal.toLowerCase() != this._defaultBlankImage);
				
				if(shouldShowImage)
					s = "<img class='ksg-grid-cellEditor' cellType='image' tabindex='0' src='"+resourceUrl+"${mediaCacheName}/"+imageSize+"/${" + fieldName + "}' />";
				else				
					s = "<img class='ksg-grid-cellEditor' cellType='image' tabindex='0' src='/images/blank.gif' />";
				return s;
			},
			edit: function(grid, $gcol, $cell, col, bizObj) {
				$cell.focus();
			}		
		},
		/**
		* @class
		* Displays a dropdown widget when in edit mode, but shows the selected value as text when not in edit mode.
		*/
		dropdown: {
			std: function(grid, col, bizObj, isEditable) {
				var s = "<div tabindex='0' class='ksg-grid-cellEditor'  cellType='dropdown'";
				var fieldName = grid._getDataFieldId(col); 
				var v = "${" + fieldName + "}";
				try {
					if(!grid.dataHandler.hasValue(bizObj,fieldName))
						v = "";
				}
				catch(e) {
					v = "";
				}
				s += ">" + v + "</div>";
				return s;
			},
			edit: function(grid, $gcol, $cell, col, bizObj) {
				$gcol.attr('pr', $gcol.html());
				$gcol.html("<select style='margin:0px;padding:0px;width:100%' cellType='dropdown' class='ksg-grid-cellEditor'><option>abd</option><option>123</option></select>");
				$newCell = $gcol.find(".ksg-grid-cellEditor");
				$newCell.focus();
			},
			completeEdit: function(grid, $gcol, $cell, col, bizObj) {
				$gcol.html($gcol.attr('pr'));
			}
			
		}
	});

})(jQuery);
